import { http } from "@/utils/http";

/**
 * 查询参数（分页 + 条件）
 */
export interface DangerSourceListCommand extends BasePageQuery {
  dangerSourceName?: string;
  dangerType?: string;
  actionMakerName?: string;
}

/**
 * 响应数据结构
 */
export interface DangerSourcePageResponse {
  dangerSourceId: number;
  dangerSourceCode: string;
  dangerSourceName: string;
  dangerType?: string;
  dangerSourceDescribe?: string;
  harmDescribe?: string;
  emergeCause?: string;
  rootCause?: string;
  relatedReformId?: number;
  relatedReformCode?: string;
  correctiveAction?: string;
  correctiveDeadline?: string;
  precautionAction?: string;
  precautionDeadline?: string;
  actionMakerName?: string;
  actionMakeTime?: string;
  riskCode?: string;
  createTime: string;
}

/**
 * 获取危险源分页列表
 */
export function getDangerSourceListApi(params: DangerSourceListCommand) {
  return http.request<ResponseData<PageDTO<DangerSourcePageResponse>>>(
    "get",
    "/airport/danger-source/list",
    {
      params
    }
  );
}

/**
 * 导出危险源 Excel
 */
export const exportDangerSourceExcelApi = (
  params: DangerSourceListCommand,
  fileName: string
) => {
  return http.download("/airport/danger-source/excel", fileName, {
    params
  });
};

/**
 * 删除危险源
 */
export const deleteDangerSourceApi = (data: Array<number>) => {
  return http.request<ResponseData<void>>("delete", "/airport/danger-source", {
    params: {
      ids: data.toString()
    }
  });
};

/**
 * 新增命令结构
 */
export interface AddDangerSourceCommand {
  dangerSourceId: number;
  dangerSourceCode: string;
  dangerSourceName: string;
  dangerType?: string;
  dangerSourceDescribe?: string;
  harmDescribe?: string;
  emergeCause?: string;
  rootCause?: string;
  relatedReformId?: number;
  relatedReformCode?: string;
  correctiveAction?: string;
  correctiveDeadline?: string;
  precautionAction?: string;
  precautionDeadline?: string;
  actionMakerName?: string;
  actionMakeTime?: string;
  riskCode?: string;
  createTime: string;
}

/**
 * 新增危险源
 */
export const addDangerSourceApi = (data: AddDangerSourceCommand) => {
  return http.request<ResponseData<void>>("post", "/airport/danger-source", {
    data
  });
};

/**
 * 更新命令结构
 */
export interface UpdateDangerSourceCommand extends AddDangerSourceCommand {
  dangerSourceId: number;
  dangerSourceCode: string;
  dangerSourceName: string;
  dangerType?: string;
  dangerSourceDescribe?: string;
  harmDescribe?: string;
  emergeCause?: string;
  rootCause?: string;
  relatedReformId?: number;
  relatedReformCode?: string;
  correctiveAction?: string;
  correctiveDeadline?: string;
  precautionAction?: string;
  precautionDeadline?: string;
  actionMakerName?: string;
  actionMakeTime?: string;
  riskCode?: string;
  createTime: string;
}

/**
 * 更新危险源
 */
export const updateDangerSourceApi = (data: UpdateDangerSourceCommand) => {
  return http.request<ResponseData<void>>("put", "/airport/danger-source", {
    data
  });
};
